home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / tf-3.000 / tf-3 / tf3.0a21 / Build next >
Text File  |  1993-09-28  |  19KB  |  666 lines

  1. #!/bin/sh
  2. ###########################################################################
  3. #  TinyFugue builder
  4. ###########################################################################
  5. #  Don't edit this file.
  6. #
  7. #  If Build has trouble, or you want to change some defaults or enable
  8. #  some optional features, see README and edit the Config file.
  9. #
  10. #  Just type "Build" to install everything.
  11. ###########################################################################
  12.  
  13. ### A few portability notes.
  14. # Some versions of 'test' have the wrong precedence for unary operators,
  15. # so we use the shell's '&&' and '||' operators instead of '-a' and '-o'.
  16. # 4.3 BSD 'test' does not have '-x'.  Use '-f' or '-r' instead.
  17. # Some old shells do not support the ':' in ${VAR:-default}.  Don't use it.
  18.  
  19. ### Initialize variables, just in case they're already defined.
  20.  
  21. ANSI_C=0
  22. BINDIR=''
  23. CC=''
  24. CCFLAGS=''
  25. CONNECT=''
  26. EXE=''
  27. FLAGS=''
  28. GNU_C=0
  29. HELPFILE=''
  30. INCDIR=''
  31. LIBC=''
  32. LIBDIR=''
  33. LIBS=''
  34. MAILDIR=''
  35. MAKE=''
  36. MANPAGE=''
  37. MANTYPE=''
  38. OPT=''
  39. POSIX=1
  40. #POSIX=unknown
  41. RAND=''
  42. RESTRICT=''
  43. SYSTEM=''
  44. TERMINAL=''
  45. TFCONNECT=''
  46. TFLIBRARY=''
  47. TTYDRIVER=''
  48.  
  49. if [ ! -f ./Build ]; then
  50.     echo "You should run Build in the directory extracted from the archive."
  51.     exit 2
  52. fi
  53.  
  54. VERSION=`egrep 'char version' src/main.c | sed 's/^.*\"\(.*\)\".*$/\1/'`
  55.  
  56. {
  57. ### Everything after this point is logged to Build.log
  58.  
  59. echo "Building:  $VERSION"
  60.  
  61. ### Read in user definitions.
  62. if [ -r ./Config ]; then . ./Config; fi
  63.  
  64. ### I keep development definitions in dev/config so I don't have to keep
  65. ### editing the default version.
  66. if [ -r dev/config ]; then . dev/config; fi
  67.  
  68. ### Make sure the PATH is sane.
  69. PATH="/bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/local:/usr/lbin:/etc:/usr/new:/usr/new/bin:/usr/nbin:$PATH"
  70.  
  71. if [ -z "$INCDIR" ]; then
  72.     INCDIR='/usr/include'
  73. fi
  74.  
  75. # ### Try to detect ability to support nonblocking connect
  76. #
  77. # ### This doesn't work.  Some systems (notably SunOS) define I_SENDFD
  78. # ### and I_RECVFD, but don't actually support it.  And, OSF defines
  79. # ### SCM_RIGHTS, but then requires special hacks to get 4.4 BSD behavior.
  80. # if [ -z "$CONNECT" ]; then
  81. #     if egrep 'I_SENDFD' ${INCDIR}/stropts.h >/dev/null 2>&1; then
  82. #         CONNECT='CONNECT_SVR4'
  83. #         echo 'Your system appears to support nonblocking connect.'
  84. #     elif egrep 'SCM_RIGHTS' ${INCDIR}/sys/socket.h >/dev/null 2>&1; then
  85. #         CONNECT='CONNECT_BSD'
  86. #         echo 'Your system appears to support nonblocking connect.'
  87. #     fi
  88. # else
  89. if [ "$CONNECT" = "blocking" ]; then
  90.     CONNECT=''
  91. fi
  92.  
  93. ### Pick user's or default definitions.
  94.  
  95. if [ -w /usr/local/bin ] && [ -w /usr/local/lib ]; then
  96.     BINDIR=/usr/local/bin
  97.     LIBDIR=/usr/local/lib
  98. else
  99.     [ -d $HOME/bin ] && BINDIR=$HOME/bin || BINDIR=$HOME
  100.     [ -d $HOME/lib ] && LIBDIR=$HOME/lib || LIBDIR=$HOME
  101. fi
  102.  
  103. [ -z "$EXE" ]       && EXE=${BINDIR}/tf
  104. [ -z "$TFLIBRARY" ] && TFLIBRARY=${LIBDIR}/tf.library
  105. [ -z "$TFCONNECT" ] && TFCONNECT=${BINDIR}/tf.connect
  106. [ -z "$HELPFILE" ]  && HELPFILE=${LIBDIR}/tf.help
  107. [ -z "$MODE" ]      && MODE=755
  108.  
  109. if [ -z "$CONNECT" ]; then
  110.     TFCONNECT=""
  111. fi
  112.  
  113. ### Build DEFS list.
  114.  
  115. DEFS="$DEFS EXE=${EXE} TFLIBRARY=${TFLIBRARY} HELPFILE=${HELPFILE}"
  116. DEFS="$DEFS MAKE=${MAKE} MODE=${MODE}"
  117. # DEFS="$DEFS MODE=${MODE}"
  118.  
  119. if [ -n "$TFCONNECT" ]; then
  120.     DEFS="$DEFS TFCONNECT=${TFCONNECT}"
  121. else
  122.     CONNECT=""
  123. fi
  124.  
  125. if [ -n "$MANPAGE" ]; then
  126.     [ -z "$MANTYPE" ] && MANTYPE=cat
  127.     DEFS="$DEFS MANTYPE=${MANTYPE} MANPAGE=${MANPAGE}"
  128. fi
  129.  
  130. ### Sanity check for filenames (some people do pretty stupid things)
  131.  
  132. if echo "$TFLIBRARY" | egrep "^[^/~]" ||
  133.    echo "$HELPFILE"  | egrep "^[^/~]" ||
  134.    echo "$EXE"       | egrep "^[^/~]"
  135. then
  136.    echo "You should not use relative paths to install files."
  137.    echo "Edit Config and try again."
  138.    exit 2
  139. fi
  140.  
  141.  
  142. if echo "$TFLIBRARY" | egrep "^`/bin/pwd`/" ||
  143.    echo "$HELPFILE"  | egrep "^`/bin/pwd`/" ||
  144.    echo "$EXE"       | egrep "^`/bin/pwd`/"
  145. then
  146.     echo "You should not install files in `/bin/pwd`."
  147.     echo "Edit Config and try again."
  148.     exit 2
  149. fi
  150.  
  151. if echo "$TFLIBRARY" | egrep "^~" >/dev/null; then
  152.     TFLIBRARY=`echo $TFLIBRARY | sed "s;~;$HOME;"`
  153. fi
  154. if echo "$HELPFILE"  | egrep "^~" >/dev/null; then
  155.     HELPFILE=`echo $HELPFILE | sed "s;~;$HOME;"`
  156. fi
  157. if echo "$EXE"       | egrep "^~" >/dev/null; then
  158.     EXE=`echo $EXE | sed "s;~;$HOME;"`
  159. fi
  160.  
  161. ### Find mail directory by looking at $MAIL, then looking in the usual places.
  162.  
  163. if [ -z "$MAILDIR" ]; then
  164.     if [ -n "$MAIL" ]; then
  165. #       Not everybody has dirname.  sigh.
  166.         MAILDIR=`echo $MAIL | sed 's;[^/]*$;;'`
  167.     elif [ -d /usr/spool/mail ]; then
  168.         MAILDIR="/usr/spool/mail/"
  169.     elif [ -d /var/spool/mail ]; then
  170.         MAILDIR="/var/spool/mail/"
  171.     elif [ -d /usr/mail ]; then
  172.         MAILDIR="/usr/mail/"
  173.     elif [ -d /var/mail ]; then
  174.         MAILDIR="/var/mail/"
  175.     else
  176.         MAILDIR=""
  177.     fi
  178. fi
  179.  
  180.  
  181. ### Confirm.
  182.  
  183. if [ -z "$*" ]; then
  184.     echo
  185.     echo "TF binary will be installed in    $EXE"
  186.     echo "Library will be installed in      $TFLIBRARY"
  187.     if [ -n "$CONNECT" ]; then
  188.         echo "Connector will be installed in    $TFCONNECT"
  189.     else
  190.         echo "Nonblocking connect will not be enabled."
  191.     fi
  192.     if [ -n "$HELPFILE" ]; then
  193.         echo "Helpfile will be installed in     $HELPFILE"
  194.     else
  195.         echo "Online help will not be available."
  196.     fi
  197.     if [ -n "$MAILDIR" ]; then
  198.         echo "Mail will be checked in directory $MAILDIR"
  199.     else
  200.         echo "Mail directory unknown.  TF may not be able to check mail."
  201.     fi
  202.     if [ -n "$MANPAGE" ]; then
  203.         echo "Man page will be installed in     $MANPAGE in $MANTYPE format"
  204.     else
  205.         echo "Man page will not be installed."
  206.     fi
  207.     echo
  208.     echo 'To change these defaults type "n" now and edit the Config file.'
  209.     while [ -z "$ans" ]; do
  210.         echo 'Continue? (y/n)'
  211.         read ans;
  212.         case "$ans" in
  213.         y|Y)  break
  214.               ;;
  215.         n|N)  exit 1
  216.               ;;
  217.         *)    ans=
  218.               echo 'Please answer "y" or "n".'
  219.               ;;
  220.         esac
  221.     done
  222. fi
  223.  
  224.  
  225. ### Compiler.
  226. ### SVr4 and some others have a "ucb" compiler that works better with socket
  227. ### stuff (e.g., automatically links in -lsocket -lnsl), so look for that.
  228. ### Otherwise, use GNU C if it's available.
  229. ### Note that GNU C's -ansi option does not guarantee existance of ANSI
  230. ### headers or libraries, so we must still verify them seperately.
  231.  
  232. if [ -z "$CC" ]; then
  233.     if [ -f /usr/ucb/cc-bsd ]; then
  234.         CC='/usr/ucb/cc-bsd'
  235.         CCFLAGS='-g'
  236.         echo "Your system has /usr/ucb/cc-bsd.  I'll try that."
  237.     elif [ -f /usr/ucb/cc ]; then
  238.         CC='/usr/ucb/cc'
  239.         CCFLAGS='-g'
  240.         echo "Your system has /usr/ucb/cc.  I'll try that."
  241.     elif { gcc -v; } > /dev/null 2>&1; then
  242.         CC='gcc'
  243.         CCFLAGS="-O -ansi $CCFLAGS"
  244. #        CCFLAGS="-g -ansi $CCFLAGS"
  245.         ANSI_C=1
  246.         GNU_C=1
  247.         echo "Your system has gcc.  Cool.  I'll use it."
  248.     else
  249.         CC='cc'
  250.         CCFLAGS='-g'
  251.         echo "I'll use cc to compile."
  252.     fi
  253. fi
  254.  
  255. DEFS="$DEFS CC=${CC}"
  256.  
  257. ### Test for ANSI.
  258. ### ansi.c returns 1 for GNU C, 0 for any other ANSI compiler, 2 otherwise.
  259.  
  260. if [ "$ANSI_C" != "1" ]; then
  261.     cat > ansi.c <<EOP
  262. main() {
  263. #ifdef __GNUC__
  264.     exit(1);
  265. #endif
  266. #ifdef __STDC__
  267. # if __STDC__ == 1
  268.     exit(0);
  269. # endif
  270. #endif
  271.     exit(2);
  272. }
  273. EOP
  274.     ${CC} ${CCFLAGS} ${FLAGS} ansi.c >/dev/null 2>&1
  275.     if [ $? != 0 ] ; then
  276.         echo "Ack!  Your compiler doesn't work.  Maybe you used invalid flags."
  277.         echo "Edit Config and fix it.  I give up."
  278.         exit 2
  279.     fi
  280.     ./a.out
  281.     result=$?
  282.     if [ $result = 0 ]; then
  283.         echo "Cool, you have an ANSI compiler."
  284.         ANSI_C=1
  285.     elif [ $result = 1 ]; then
  286.         echo "Ah ha, ${CC} is really GNU C.  Cool, I'll use it with -ansi."
  287.         ANSI_C=1
  288.         GNU_C=1
  289.         CCFLAGS="${CCFLAGS} -ansi"
  290.     else
  291.         echo "Your compiler doesn't appear to be ANSI."
  292.         ANSI_C=0
  293.     fi
  294.     rm ansi.c
  295. fi
  296.  
  297. ### Test for POSIX.
  298. ### If posix.c fails to compile, unistd.h must be missing (and system is not
  299. ### POSIX).  Otherwise, a.out returns 0 if posix, 1 if not.
  300.  
  301. if [ ${POSIX} = "unknown" ]; then
  302.     cat > posix.c <<EOP
  303. #include <unistd.h>
  304. int main() {
  305. #ifdef _POSIX_VERSION
  306.     exit(0);
  307. #else
  308.     exit(1);
  309. #endif
  310. }
  311. EOP
  312.     if ${CC} ${CCFLAGS} ${FLAGS} posix.c >/dev/null 2>&1; then
  313.         FLAGS="$FLAGS -DHAVE_UNISTD_H"
  314.         if ./a.out; then
  315.             echo "Right on, your system is POSIX."
  316.             POSIX=1
  317.         else
  318.             echo "This doesn't appear to be a POSIX system."
  319.             POSIX=0
  320.         fi
  321.     else
  322.         echo "I can't find unistd.h.  The compiler may produce a lot of"
  323.         echo "warnings, but you can probably ignore them."
  324.         echo
  325.         echo "This doesn't appear to be a POSIX system."
  326.         POSIX=0
  327.     fi
  328.     rm posix.c
  329. fi
  330.  
  331. rm a.out
  332.  
  333.  
  334. ### Try to detect unusual systems by looking for files required on those
  335. ### systems.  This is a hack.  If you can think of a better way, let me know.
  336.  
  337. if [ -z "$SYSTEM" ]; then
  338.     if { ver && lvolfs; } >/dev/null 2>&1; then
  339.         SYSTEM="DOMAIN_OS"
  340.         echo "This looks like a Domain/OS system to me."
  341.     elif [ -r ${INCDIR}/sys/in.h ] && [ -r ${INCDIR}/sys/inet.h ] && \
  342.          [ -r /usr/lib/libnet.a ] && [ -r /usr/lib/libnsl_s.a ]; then
  343.         SYSTEM="WINS"
  344.         echo "This looks like a system with WINS networking to me."
  345.     elif [ -r /usr/lib/libsocket.a ] && [ -r /usr/lib/libinet.a ] && \
  346.         [ -r /usr/lib/libnsl.a ]; then
  347.         SYSTEM="DYNIX_PTX"
  348.         echo "This looks like a Dynix/PTX system to me."
  349.     fi
  350.     if [ -n "$SYSTEM" ]; then
  351.         echo "If this is incorrect, set SYSTEM in the Config file."
  352.         echo
  353.     fi
  354. else
  355.     FLAGS="$FLAGS -D$SYSTEM"
  356. fi
  357.  
  358. case "$SYSTEM" in
  359.     WINS)
  360.         FLAGS="$FLAGS -DWINS"
  361.         LIBS="$LIBS -lnet -lnsl_s"
  362.         ;;
  363.     DYNIX_PTX)
  364.         LIBS="$LIBS -lsocket -linet -lnsl"
  365.         ;;
  366.     DOMAIN_OS)
  367.         FLAGS="$FLAGS -U__STDC__"
  368.         ;;
  369. esac
  370.  
  371. ### This isn't required, but it helps.
  372. if [ -r ${INCDIR}/stdlib.h ]; then
  373.     FLAGS="$FLAGS -DHAVE_STDLIB_H"
  374. elif [ "$ANSI_C" = "1" ] && [ "$GNU_C" = "0" ]; then
  375.     FLAGS="$FLAGS -DHAVE_STDLIB_H"
  376. else
  377.     echo "I can't find stdlib.h.  The compiler may produce a lot of"
  378.     echo "warnings, but you can probably ignore them."
  379.     echo
  380. fi
  381.  
  382. ### Figure out which string file to include, if compiler isn't ANSI.
  383. if [ "$ANSI_C" = "1" ] && [ "$GNU_C" = 0 ]; then
  384.     FLAGS="$FLAGS -DUSE_STRING_H"
  385. elif [ -r ${INCDIR}/string.h ]; then
  386.     FLAGS="$FLAGS -DUSE_STRING_H"
  387. elif [ -r ${INCDIR}/strings.h ]; then
  388.     FLAGS="$FLAGS -DUSE_STRINGS_H"
  389. else
  390.     echo "    I can't find string.h or strings.h.  I'll try to use string.h."
  391.     FLAGS="$FLAGS -DUSE_STRING_H"
  392. fi
  393.  
  394. ### This isn't required, but it helps.
  395. if [ -r ${INCDIR}/sys/wait.h ]; then
  396.     FLAGS="$FLAGS -DHAVE_SYS_WAIT_H"
  397. else
  398.     echo "    I can't find sys/wait.h.  No big deal."
  399. fi
  400.  
  401. ### Look through the contents of the C library to see if certain functions
  402. ### are available.  This is a bit of a hack.  But hey, it works.  Most of
  403. ### the time, anyway.
  404.  
  405. echo "Checking your system for availability of certain features..."
  406.  
  407. if [ -z "$LIBC" ] || [ ! -f "$LIBC" ]; then
  408.     if [ -r /lib/libc.a ]; then
  409.         LIBC='/lib/libc.a'
  410.     elif [ -r /usr/lib/libc.a ]; then
  411.         LIBC='/usr/lib/libc.a'
  412.     elif [ -r /usr/ccs/lib/libc.a ]; then
  413.         LIBC='/usr/ccs/lib/libc.a'
  414.     elif [ -r /usr/lib/libNeXT_s.a ]; then
  415.         LIBC='/usr/lib/libNeXT_s.a'
  416.     else
  417.         LIBC=''
  418.     fi
  419. fi
  420.  
  421. if [ -n "$LIBC" ]; then
  422.     echo "    Found C library in $LIBC."
  423.     echo "    The next step may be slow.  Be patient."
  424.     nm $LIBC >libc.list 2>/dev/null
  425.     if [ ! -s libc.list ]; then ar t $LIBC >libc.list 2>/dev/null; fi
  426. else
  427.     echo "    I can't find your C library!"
  428.     echo "    I'll need to make some assumptions.  If I'm wrong, edit Config."
  429.     :>libc.list
  430. fi
  431.  
  432. ### Look for rand() or random().
  433. ### rand() is ANSI, but random() is more random.
  434.  
  435. if [ -z "$RAND" ]; then
  436.     if egrep '(^|[^a-z])random([^a-z]|$)' libc.list >/dev/null 2>&1; then
  437.         echo "    Found random() in your C library."
  438.         RAND='-DRANDOM=random -DSRANDOM=srandom'
  439.     elif egrep '(^|[^a-z])rand([^a-z]|$)' libc.list >/dev/null 2>&1; then
  440.         echo "    Found rand() in your C library."
  441.         RAND='-DRANDOM=rand -DSRANDOM=srand'
  442.     elif [ "$ANSI_C" = "1" ]; then
  443.         RAND='-DRANDOM=rand -DSRANDOM=srand'
  444.         echo "    Since this is ANSI, I'm assuming you have rand()."
  445.     else
  446.         RAND='-DRANDOM=rand -DSRANDOM=srand'
  447.         echo "    I can't find rand() or random().  I'll assume you have"
  448.         echo "    rand().  If not, edit the RAND line in the Config file."
  449.     fi
  450. fi
  451. FLAGS="$FLAGS $RAND"
  452.  
  453. ### If this is POSIX, use getcwd().  If not, see if getcwd(), getwd(),
  454. ### or neither is available.  This isn't vital.
  455.  
  456. if [ "$POSIX" = "1" ]; then
  457.     FLAGS="$FLAGS -DHAVE_GETCWD"
  458. elif egrep '(^|[^a-z])getcwd([^a-z]|$)' libc.list >/dev/null 2>&1; then
  459.     echo "    Found getcwd() in your C library."
  460.     FLAGS="$FLAGS -DHAVE_GETCWD"
  461. elif egrep '(^|[^a-z])getwd([^a-z]|$)' libc.list >/dev/null 2>&1; then
  462.     echo "    Found getwd() in your C library."
  463.     FLAGS="$FLAGS -DHAVE_GETWD"
  464. else
  465.     echo "    I can't find getwd() or getcwd().  No big deal."
  466. fi
  467.  
  468. ### Look for memcpy() or bcpy().
  469.  
  470. if egrep '(^|[^a-z])memcpy([^a-z]|$)' libc.list >/dev/null 2>&1; then
  471.     echo "    Found mempcy() in your C library."
  472.     FLAGS="$FLAGS -DHAVE_MEMCPY"
  473. elif egrep '(^|[^a-z])bcpy([^a-z]|$)' libc.list >/dev/null 2>&1; then
  474.     echo "    Found bcpy() in your C library."
  475.     FLAGS="$FLAGS -DHAVE_BCPY"
  476. else
  477.     echo "    I can't find memcpy() or bcpy().  Good luck."
  478.     if [ "$ANSI_C" = "1" ]; then
  479.         echo "    Since this is ANSI, I'll assume you have memcpy()."
  480.     else
  481.         echo "    I'll assume you have bcpy()."
  482.     fi
  483. fi
  484.  
  485. ### Look for strchr() or index().
  486.  
  487. if egrep '(^|[^a-z])strchr([^a-z]|$)' libc.list >/dev/null 2>&1; then
  488.     echo "    Found strchr() in your C library."
  489.     FLAGS="$FLAGS -DHAVE_STRCHR"
  490. elif egrep '(^|[^a-z])index([^a-z]|$)' libc.list >/dev/null 2>&1; then
  491.     echo "    Found index() in your C library."
  492.     FLAGS="$FLAGS -DHAVE_INDEX"
  493. else
  494.     echo "    I can't find strchr() or index().  Good luck."
  495.     if [ "$ANSI_C" = "1" ]; then
  496.         echo "    Since this is ANSI, I'll assume you have strchr()."
  497.     else
  498.         echo "    I'll assume you have index()."
  499.     fi
  500. fi
  501.  
  502. ### Look for strstr().
  503.  
  504. if egrep '(^|[^a-z])strstr([^a-z]|$)' libc.list >/dev/null 2>&1; then
  505.     echo "    Found strstr() in your C library."
  506.     FLAGS="$FLAGS -DHAVE_STRSTR"
  507. else
  508.     echo "    I can't find strstr().  That's okay, I'll use my own."
  509. fi
  510.  
  511. ### Look for strtol().
  512.  
  513. if egrep '(^|[^a-z])strtol([^a-z]|$)' libc.list >/dev/null 2>&1; then
  514.     echo "    Found strtol() in your C library."
  515.     FLAGS="$FLAGS -DHAVE_STRTOL"
  516. else
  517.     echo "    I can't find strtol().  That's okay, I'll use my own."
  518. fi
  519.  
  520. ### If we can't find gethostbyname() in libc, look for libresolv.
  521.  
  522. if [ "$SYSTEM" = "DYNIX_PTX" ] || [ "$SYSTEM" = "WINS" ]; then
  523.     : We already know where to find the network libraries.
  524. elif egrep '(^|[^a-z])gethostbyname([^a-z]|$)' libc.list >/dev/null 2>&1; then
  525.     echo "    Found gethostbyname() in your C library."
  526. else
  527.     echo "    Your C library doesn't have gethostbyname()."
  528.     if [ -r /lib/libresolv.a ]; then
  529.         RESOLV='/lib/libresolv.a';
  530.     elif [ -r /usr/lib/libresolv.a ]; then
  531.         RESOLV='/usr/lib/libresolv.a';
  532.     elif [ -r /usr/ccs/lib/libresolv.a ]; then
  533.         RESOLV='/usr/ccs/lib/libresolv.a';
  534.     else
  535.         RESOLV=''
  536.     fi
  537.     if [ -n "$RESOLV" ]; then
  538.         echo "    But, your system does have $RESOLV.  I'll link that in."
  539.         LIBS="$LIBS -lresolv"
  540.     else
  541.         echo "    And, I can't find a 'resolv' library.  Good luck."
  542.     fi
  543. fi
  544.  
  545. rm libc.list
  546.  
  547. ### Figure out which terminal driver to use.
  548.  
  549. if [ "$POSIX" = "1" ]; then
  550.     if [ -z "$TTYDRIVER" ]; then
  551.         TTYDRIVER=-DUSE_TERMIOS
  552.     fi
  553. elif [ -z "$TTYDRIVER" ]; then
  554.     if [ -r ${INCDIR}/termios.h ]; then
  555.         echo "    Your system has termios.h, but doesn't define _POSIX_VERSION?"
  556.         echo "    Okay, I'll use termios.h.  Edit Config if it doesn't work."
  557.         TTYDRIVER="-DUSE_TERMIOS"
  558.     elif [ -r ${INCDIR}/termio.h ] && [ -r ${INCDIR}/sgtty.h ]; then
  559.         echo "    Your system has both termio.h and sgtty.h, but not termios.h."
  560. #       Make a semi-educated guess, and warn the user.
  561. #       Many USG systems have uname, many BSD systems don't.
  562.         if { uname; } >/dev/null 2>&1; then
  563.             TTYDRIVER="-DUSE_TERMIO"
  564.             echo "    I'm going to assume I should use termio.h."
  565.             echo "    If I'm wrong, set TTYDRIVER='-DUSE_SGTTY' in Config."
  566.         else
  567.             TTYDRIVER="-DUSE_SGTTY"
  568.             echo "    I'm going to assume I should use sgtty.h."
  569.             echo "    If I'm wrong, set TTYDRIVER='-DUSE_TERMIO' in Config."
  570.         fi
  571.     elif [ -r ${INCDIR}/termio.h ]; then
  572. #       Only termio.h is available.
  573.         echo "    Your system has termio.h."
  574.         TTYDRIVER="-DUSE_TERMIO"
  575.     elif [ -r ${INCDIR}/sgtty.h ] || [ -r ${INCDIR}/bsd/sgtty.h ]; then
  576. #       Only sgtty.h is available.
  577.         echo "    Your system has sgtty.h."
  578.         TTYDRIVER="-DUSE_SGTTY"
  579.     else
  580.         echo "    I can't find any terminal driver headers on your system!"
  581.         echo "    I'm going to try using sgtty.h anyway."
  582.         echo "    If I'm wrong, edit Config and set TTYDRIVER yourself."
  583.     fi
  584. fi
  585. FLAGS="$FLAGS $TTYDRIVER"
  586.  
  587. if [ -z "$TERMINAL" ]; then
  588.     TERMINAL=-DTERMCAP
  589. fi
  590. if [ "$TERMINAL" = "-DTERMCAP" ]; then
  591.     LIBS="$LIBS -ltermcap"
  592. fi
  593.  
  594. DEFS="$DEFS MAILDIR=${MAILDIR}"
  595.  
  596. ### If there were command line arguments, those are the make targets.
  597. ### Otherwise, make the default targets.
  598.  
  599. if [ -n "$*" ]; then
  600.     TARGETS="$*"
  601. else
  602.     TARGETS="$EXE $TFLIBRARY"
  603.     if [ -n "$CONNECT" ]; then
  604.         TARGETS="$TARGETS $TFCONNECT"
  605.     fi
  606.     if [ "$HELPFILE" != "/dev/null" ]; then
  607.         TARGETS="$TARGETS HELP"
  608.     fi
  609.     if [ -n "$MANPAGE" ]; then
  610.         TARGETS="$TARGETS $MANPAGE"
  611.     fi
  612. fi
  613.  
  614. if [ -n "$CONNECT" ]; then
  615.     FLAGS="$FLAGS -D$CONNECT"
  616. fi
  617.  
  618. FLAGS="$FLAGS $TERMINAL $RESTRICT $CCFLAGS"
  619.  
  620. OBJS="main.o world.o util.o socket.o keyboard.o macro.o search.o \
  621. command1.o command2.o special.o history.o process.o output.o \
  622. expand.o dstring.o help.o signal.o variable.o tfio.o malloc.o"
  623.  
  624. if [ -z "$CONNECT" ]; then
  625.     OBJS="$OBJS opensock.o"
  626. fi
  627.  
  628. if [ -n "$DMALLOC" ]; then
  629.     FLAGS="$FLAGS -DDMALLOC"
  630.     OBJS="$OBJS dmalloc.o"
  631. fi
  632.  
  633. ### Last chance.
  634.  
  635. echo
  636. echo "#### If any of my assumptions were wrong, press ^C now and edit Config."
  637. echo
  638.  
  639. ### Do it.
  640.  
  641. cd ./src
  642.  
  643. echo "$MAKE $DEFS FLAGS=\"$FLAGS\" LIBS=\"$LIBS\" OBJS=\"$OBJS\" \
  644.     OPT=\"$OPT\" $TARGETS"
  645.  
  646. if $MAKE $DEFS FLAGS="$FLAGS" LIBS="$LIBS" OBJS="$OBJS" OPT="$OPT" $TARGETS
  647. then
  648.     if [ -z "$*" ]; then
  649.         echo
  650.         echo "#### TinyFugue Build successful."
  651.         echo "#### You may remove the `/bin/pwd` directory if you wish."
  652.         echo "#### But first check out CHANGES and examples."
  653.     fi
  654. else
  655.     echo
  656.     echo '#### TinyFugue Build FAILED.'
  657.     echo '#### Read README to find out how to correct the problem.'
  658. fi
  659.  
  660. } 2>&1 | tee Build.log
  661.